package com.tanhua.manage.interceptor;

import com.tanhua.manage.domain.Admin;

/**
 * 通过ThreadLocal对象，存储用户的数据
 * 1、声明ThreadLocal对象
 * 2、向当前线程存储数据：threadLocal.set();
 * 3、从当前线程获取数据：threadLocal.get();
 */
public class AdminHolder {

    private static ThreadLocal<Admin> threadLocal = new ThreadLocal<>();


    /**
     * 将用户信息设置到当前线程
     */
    public static void set(Admin admin) {
        threadLocal.set(admin);
    }

    /**
     * 从当前线程获取用户信息
     */
    public static Admin get() {
        return threadLocal.get();
    }

    /**
     * 从当前线程获取用户ID
     */
    public static Long getUserId() {
        return get().getId();
    }



}
